/**
 * 
 */
package lu.med.praxiswahl.wahlumed.client.zytologie;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.table.TableColumn;

import lu.med.praxiswahl.wahlumed.client.utilities.ColumnWidthControler;

/**
 * @author PatrickPierre
 * 
 */
public class TableHeaderMouseListener extends MouseAdapter {

	private ZytologieTable tableObj;
	private ColumnWidthControler colControler;

	public TableHeaderMouseListener(ZytologieTable tableObj,
			ColumnWidthControler colControler) {
		this.tableObj = tableObj;
		this.colControler = colControler;
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		/* On mouse release, check if column width has changed */
		if (tableObj.getColumnWidthChanged()) {

			TableColumn resizedColumn = tableObj.getResizedColumn();
			String changedHeader = resizedColumn.getHeaderValue().toString();

			try {
				// Get the config tag
				String configTag = this.colControler.getTableColumnConfigTag();
				
				this.colControler.getReader().resetValueOfDeepedTag(configTag, changedHeader, ""+resizedColumn.getPreferredWidth());
				
				
			} catch (java.lang.NullPointerException ex) {
				resizedColumn = null;
			}
			
			// Updates the tableConfiguration xml document
			this.colControler.getReader().updateDocument();

			// Reset the flag on the table.
			tableObj.setColumnWidthChanged(false, null);
		}
	}

}
